local js_niluan = fk.CreateSkill {
  name = "js__niluan",
}

js_niluan:addEffect(fk.EventPhaseStart, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Start
  end,
  on_cost = function(self, event, target, player, data)
    local success, dat = player.room:askForUseActiveSkill(player, "js__niluan_active", "#js__niluan-invoke", true)
    if success and dat then
      event:setCostData(self,{tos = dat.targets, cards = dat.cards})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(event:getCostData(self).tos[1])
    player:broadcastSkillInvoke(self.name)
    if #event:getCostData(self).cards > 0 then
      room:notifySkillInvoked(player, self.name, "offensive")
      room:throwCard(event:getCostData(self).cards, self.name, player, player)
      if to.dead then return end
      room:damage({
        from = player,
        to = to,
        damage = 1,
        skillName = self.name
      })
    else
      room:notifySkillInvoked(player, self.name, "support")
      to:drawCards(2, self.name)
    end
  end,
})

return js_niluan